#ifndef __PRINTK_H__
#define __PRINTK_H__

#include "libs/types.h"
#include "stdarg.h"
#include "libs/spinlock.h"

#define ZEROPAD	1		/* pad with zero */
#define SIGN	2		/* unsigned/signed long */
#define PLUS	4		/* show plus */
#define SPACE	8		/* space if plus */
#define LEFT	16		/* left justified */
#define SPECIAL	32		/* 0x */
#define SMALL	64		/* use 'abcdef' instead of 'ABCDEF' */

#define is_digit(c)	((c) >= '0' && (c) <= '9')

#define WHITE 	0x00ffffff		//白
#define BLACK 	0x00000000		//黑
#define RED	0x00ff0000		//红
#define ORANGE	0x00ff8000		//橙
#define YELLOW	0x00ffff00		//黄
#define GREEN	0x0000ff00		//绿
#define BLUE	0x000000ff		//蓝
#define INDIGO	0x0000ffff		//靛
#define PURPLE	0x008000ff		//紫



#define LOG_INFO \
vbelog::info_printk
#define LOG_ERROR \
vbelog::error_printk
#define LOG_WARN \
vbelog::warn_printk

extern uint64_t isSMP;
extern uint64_t isInterrupt;

#define do_div(n,base) ({ \
int __res; \
__asm__("divq %%rcx":"=a" (n),"=d" (__res):"0" (n),"1" (0),"c" (base)); \
__res; })


void putchar(unsigned int * fb,int Xsize,int x,int y,unsigned int FRcolor,unsigned int BKcolor,unsigned char font);
char * number(char * str, long num, int base, int size, int precision,	int type);
int vsprintf(char * buf,const char *fmt, va_list args);
int skip_atoi(const char **s);

struct VbeCache
{
    uint32_t* buffer;
    int x;
    int y;
    int maxLine;

};



class vbelog
{
private:
    
    /* data */
    int32_t XResolution;
    int32_t YResolution;


    int32_t XPosition;
	int32_t YPosition;

	int32_t XCharSize;
	int32_t YCharSize;

    int32_t YMaxSize;
	

    uint32_t FRcolor;
    uint32_t BKcolor;
    Spinlock logSpinlock;
    char buf[4096]={0};
    int logInitFinish;
    VbeCache cache;
public:
    uint32_t * FB_addr;
	uint64_t FB_length;

    static vbelog* vbe;
    vbelog(/* args */);
    ~vbelog();
    static uint32_t color_printk(const char* fmt, ...);
    static uint32_t info_printk(const char* fmt, ...);
    static uint32_t error_printk(const char* fmt, ...);
    static uint32_t warn_printk(const char* fmt, ...);
    static uint32_t color_printk(uint32_t FRcolor, uint32_t BKcolor, const char* fmt,...);
    uint32_t color_printk(uint32_t FRcolor, uint32_t BKcolor, const char* fmt,va_list args);

    void initCache();
    
};














#endif